from typing import List


class Solution:
    def maxBoxesInWarehouse(self, boxes: List[int], warehouse: List[int]) -> int:
        for i in range(1, len(warehouse)):
            warehouse[i] = min(warehouse[i], warehouse[i - 1])

        boxes.sort(reverse=True)

        ans = 0
        j = 0
        for i in range(len(warehouse)):
            while j < len(boxes) and boxes[j] > warehouse[i]:
                j += 1
            if j < len(boxes):
                ans += 1
                j += 1

        return ans


if __name__ == "__main__":
    print(Solution().maxBoxesInWarehouse(boxes=[4, 3, 4, 1], warehouse=[5, 3, 3, 4, 1]))  # 3
    print(Solution().maxBoxesInWarehouse(boxes=[1, 2, 2, 3, 4], warehouse=[3, 4, 1, 2]))  # 3
    print(Solution().maxBoxesInWarehouse(boxes=[1, 2, 3], warehouse=[1, 2, 3, 4]))  # 1
    print(Solution().maxBoxesInWarehouse(boxes=[4, 5, 6], warehouse=[3, 3, 3, 3, 3]))  # 0
